package 强化训练;

import java.util.Scanner;
//递归通过
public class day38红与黑 {
//    public static void main(String[] args) {
//        String[][] arrs = {{".","#","."},{".","@","."},{".","#","."}};
//        String[][] arr = {
//                {".",".",".",".","#","."},
//                {".",".",".",".",".","#"},
//                {".",".",".",".",".","."},
//                {".",".",".",".",".","."},
//                {".",".",".",".",".","."},
//                {".",".",".",".",".","."},
//                {".",".",".",".",".","."},
//                {"#","@",".",".",".","#"},
//                {".","#",".",".","#","."},
//   };
//
//        System.out.println(sumOfBlack(arrs, 0, 1, 1));
//    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        sc.nextLine();
        String[][] strs = new String[m][n];
        int l = 0;
        int r = 0;
        for(int i = 0 ; i < m;i++){
            String s = sc.nextLine();
            for(int j = 0;j < s.length();j++){
                if(String.valueOf(s.charAt(j)).equals("@")){
                    l = i;
                    r = j;
                }
                strs[i][j] = String.valueOf(s.charAt(j));
            }
        }

        int count = sumOfBlack(strs,0,l,r);
        System.out.println(count);
    }

    public static int sumOfBlack(String[][] arr,int count,int i,int j){

        //1，终止条件
        if (i < 0 || i > arr.length || j < 0 || j > arr[0].length || arr[i][j].equals("#")){
            return 0;
        }

        count++;
        arr[i][j] = "@";
        int up = 0,down = 0,left = 0,right = 0;
        //否则向四个方向进行递归
        if (i > 0 && !arr[i-1][j].equals("@")){
            up = sumOfBlack(arr,count,i-1,j);
        }
        if ( i < arr.length - 1 && !arr[i+1][j].equals("@")){
            down = sumOfBlack(arr,count,i+1,j);
        }
        if (j > 0 && !arr[i][j-1].equals("@")){
            left = sumOfBlack(arr,count,i,j-1);
        }
        if (j < arr[0].length -1 && !arr[i][j+1].equals("@")){
            right = sumOfBlack(arr,count,i,j+1);
        }

        return up + down + left + right + 1;
    }
}
